<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-02 19:42:06
 * @LastEditTime: 2023-11-03 15:15:29
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Repositories;

use App\Models\CustomerStorageDetail;


class CustomerStorageDetailsRepository extends Repositories
    {
    protected $relation_models = [
        'material',
        'customer',
        'route_process',
        'status',
        'craft_category',
        'film_category',
        'salesman',
        'employee',
        'main' => ['department', 'attachments', 'location', 'inside_barcode', 'outside_barcode', 'check_unit'],
        'creator',
        'finish',
        'instorage_status',
        'self_instorage_status',
        'unit',
        'washed_index',
        'strip_index',
        'backing_category',
        'outside_barcode',
        'inside_barcode',
        'cancel'
    ];
    public function __construct(CustomerStorageDetail $model)
        {
        $this->model = $model;
        parent::__construct();
        }

    public function condition($request = null, $withauth = true)
        {
        $request = request();
        if ($request->has("filter")) {
            $filters = $request->filter;
            foreach ($filters ?? [] as $keys => $filter) {
                foreach ($filter ?? [] as $key => $value)
                    if ($key == 'isopen') {
                        if ($value == 1) {
                            $this->where("lack_quantity", ">", 0);
                            }
                        unset($filters[$keys]['isopen']);
                        }
                }

            $request->offsetSet("filter", $filters);
            }

        return parent::condition($request, $withauth);
        }
    }